<template>
  <div style="display: flex;">
    <div style="background-color: #f3f6ff; width: 50vw; height: 100vh;">
      <div>
        <img src="../assets/img/logo2.png" style="margin-left: 5vw;" alt />
      </div>
      <img src="../assets/img/beijin.png" style="width: 30vw; margin-left: 10vw;" alt />
    </div>
    <div style="width: 35vw; padding: 8vh 0 0 10vw;">
      <!-- 登录 -->
      <div style="margin: auto;" v-if="loginfales==0">
        <h1>欢迎回来！</h1>
        <h3 style="color: black;">请登录到您的账号。</h3>
        <div style="margin-top: 10vh;">
          <el-form label-width="80px" :rules="rules" :model="ruleForm">
            <el-form-item label="账号：" prop="userAccount">
              <el-input v-model="ruleForm.userAccount" placeholder="请输入用户名"></el-input>
            </el-form-item>
            <br />
            <br />
            <el-form-item label="密码：" prop="userPassword">
              <el-input
                type="password"
                show-password
                v-model="ruleForm.userPassword"
                placeholder="请输入密码"
              ></el-input>
            </el-form-item>
            <br />
            <br />
            <div class="loginclass" @click="submitForm(ruleForm)">登录</div>
          </el-form>
          <br />
          <div class="loginButto" @click="openData(1)">没有账号？立即注册</div>
        </div>
      </div>
      <div style="margin: auto;" v-if="loginfales==1">
        <h1>欢迎加入！</h1>
        <h3 style="color: black; font-size: 14px;">请注册您的账号。</h3>
        <div style="margin-top: 10vh;">
          <el-form label-width="80px" :rules="rules" :model="ruleForm">
            <el-form-item label="账号：" prop="userAccount">
              <el-input v-model="ruleForm.userAccount" placeholder="请输入账号"></el-input>
            </el-form-item>
            <br />
            <br />
            <el-form-item label="昵称：" prop="nickName">
              <el-input v-model="ruleForm.name" placeholder="请输入昵称"></el-input>
            </el-form-item>
            <br />
            <br />
            <el-form-item label="密码：" prop="userPassword">
              <el-input
                type="password"
                show-password
                v-model="ruleForm.userPassword"
                placeholder="请输入密码"
              ></el-input>
            </el-form-item>
            <br />
            <br />
            <div class="loginclass" @click="register()">注册</div>
          </el-form>
          <br />
          <div class="loginButto" @click="openData(0)">已有账号？立即登录</div>
        </div>
      </div>
    </div>
  </div>
</template>
<script type="text/ecmascript-6">
import { login, register } from "../api/login";
export default {
  name: "login",
  data() {
    return {
      loginfales: 0,
      addData: {
        imgList: []
      },
      addVisible: false,
      detailVisible: false,
      //定义loading默认为false
      logining: false,
      ruleForm: {
        userAccount: "",
        userPassword: ""
      },
      //rules前端验证
      rules: {
        userAccount: [{ required: true, message: "请输入账号", trigger: "blur" }],
        userPassword: [{ required: true, message: "请输入密码", trigger: "blur" }]
      },
      datalist: [],
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 10,
        total: 0
      }
    };
  },
  // 创建完毕状态(里面是操作)
  created() {},
  // 里面的函数只有调用才会执行
  methods: {
    register() {
      register(this.ruleForm).then(res => {
        if (res.flag) {
          this.$message({
            type: "success",
            message: "新增成功"
          });
        } else {
          this.$message({
            type: "error",
            message: res.message
          });
        }
        this.ruleForm = {};
        this.loginfales = 0;
      });
    },
    openData(type) {
      this.loginfales = type;
      this.ruleForm = {};
    },
    //获取info列表
    submitForm(formName) {
      login(formName).then(res => {
        if (res.flag) {
          this.detailVisible = true;
          this.$store.commit("LOGIN_IN", res.Authorization);
          sessionStorage.setItem("sysuser", JSON.stringify(res.user));
          setTimeout(() => {
            this.logining = false;
            this.$router.push({ path: "/home/main" });
          }, 1000);
        } else {
          this.$message.error(res.msg);
        }
      });
    }
  }
};
</script>

<style scoped>
.login-wrap {
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  padding-top: 10%;
  background-image: url();
  /* background-color: #112346; */
  background-repeat: no-repeat;
  background-position: center right;
  background-size: 100%;
}
.login-container {
  border-radius: 10px;
  margin: 0px auto;
  width: 350px;
  padding: 30px 35px 15px 35px;
  background: #fff;
  border: 1px solid #eaeaea;
  text-align: left;
  box-shadow: 0 0 20px 2px rgba(0, 0, 0, 0.1);
}
.title {
  margin: 0px auto 40px auto;
  text-align: center;
  color: #505458;
}
.remember {
  margin: 0px 0px 35px 0px;
}
.code-box {
  text-align: right;
}
.codeimg {
  height: 40px;
}

h1 {
  font-weight: 600;
  font-size: 36px;
}

h4 {
  margin-left: 3vw;
}

.loginclass {
  width: 25vw;
  height: 5.5vh;
  margin-left: 0.1vw;
  padding-top: 1.5vh;
  text-align: center;
  color: white;
  border-radius: 5px;
  background-color: #68cb9b;
  padding: 10px;
  transition: background-color 0.5s ease;
}

.loginButto {
  margin-left: 8vw;
  padding: 10px;
  transition: color 0.1s ease;
}

.loginButto:hover {
  color: aqua;
}

.loginclass:hover {
  background-color: #44ad7a;
}
</style>